#include <dirent.h> 
#include <stdio.h> 

int main(int argc, char *argv[]) {
  DIR *d;
  struct dirent *dir;

// 判断参数
  if( argc == 2 )
   {
      printf("查询的路径是 %s\n", argv[1]);
      d = opendir(argv[1]);
   }
   else if( argc > 2 )
   {
      printf("输入了太多参数.\n");
   }
   else
   {
      d = opendir(".");
   }

  if (d) {
    while ((dir = readdir(d)) != NULL) {
      printf("%s\n", dir->d_name);
    }
    closedir(d);
  }
  return(0);
}